package Eyjafjalla.action;

import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.cards.CardGroup;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;

import java.util.ArrayList;

public class ExhaustToHandAction extends AbstractGameAction {
    public ExhaustToHandAction(boolean toHand, ArrayList<AbstractCard> cards){
        this.toHand = toHand;
        this.cards = new ArrayList<>(cards);
        actionType =ActionType.CARD_MANIPULATION;
        startDuration = duration = Settings.ACTION_DUR_XFAST;
    }

    @Override
    public void update() {
        if(startDuration==duration){
            for(AbstractCard c:cards){
                if(!AbstractDungeon.player.exhaustPile.contains(c))
                    continue;
                c.stopGlowing();
                c.unhover();
                c.unfadeOut();
                if(!toHand){
                    AbstractDungeon.player.exhaustPile.moveToDiscardPile(c);
                }
                else {
                    AbstractDungeon.player.exhaustPile.moveToHand(c);
                }
                c.current_x = CardGroup.DISCARD_PILE_X;
                c.current_y = CardGroup.DISCARD_PILE_Y;
            }
            AbstractDungeon.player.hand.refreshHandLayout();
        }

        this.tickDuration();
    }

    boolean toHand;
    ArrayList<AbstractCard> cards;

}
